package UDP.test;

import javax.xml.crypto.Data;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class SendDemo {
    public static void main(String[] args) throws IOException {
        //创建发送端的Socket对象（DatagramSocket)
        DatagramSocket ds=new DatagramSocket();

        //键盘录入数据
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line=br.readLine())!=null){
            //输入886，发送数据结束
            if ("886".equals(line)){
                break;
            }

            //创建数据并将数据打包
            byte[]bys=line.getBytes();//将录入数据转为字节数组
            DatagramPacket dp=new DatagramPacket(bys, bys.length, InetAddress.getByName("LAPTOP-QF77OJO7"),12345);

            //调用DatagramSocket对象的方法发送数据
            ds.send(dp);
        }

        //关闭发送端
        ds.close();
    }
}
